﻿
Partial Class Public_ManageSearchHornorCert
    Inherits System.Web.UI.Page
    Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit
        If clsAuth.GetUserID() <> "" Then
            Me.MasterPageFile = "~\WebForm\MasterPage.master" 
        End If
        Me.Master.SiteMapProvider = SiteMap.Providers("PublicSiteMapProvider")

    End Sub
    Protected Sub btnQuery_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnQuery.Click
        Me.BindGV()
    End Sub

    Protected Sub gv_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gv.PageIndexChanging
        Me.gv.PageIndex = e.NewPageIndex
        Me.BindGV()
    End Sub
    Private Sub BindGV()
        Dim sql As New MyStringBuilder
        Dim dat As New clsData
        sql.AppendFormat(" select v.PureVolunteerName as VolunteerName,c.Text as Gender,ov.OrganizationName ")
        sql.AppendFormat(",HC.HonorCertID ")
        sql.AppendFormat(",HC.HonorCertCode ")
        sql.AppendFormat(",HC.IssueDate ")
        sql.AppendFormat(",HC.EndDate ")
        sql.AppendFormat(",HC.ApplyDate ")
        sql.AppendFormat(" from HonorCert HC ")
        sql.AppendFormat(" inner join VolunteerDistinctView v on v.VolunteerID = HC.VolunteerID ")
        sql.AppendFormat("  left JOIN (select vm.VOrganizationID,vo.VOrganizationName,vm.VolunteerID,vo.DirectUOrganizationID from VOrganizationMapping vm ")
        sql.AppendFormat("inner join VOrganizationViewV2 vo on vm.VOrganizationID=vo.VOrganizationID ) oo on v.VolunteerID=oo.VolunteerID  ")
        sql.AppendFormat(" left join OrganizationView ov on oo.DirectUOrganizationID=ov.UOrganizationID ")
        sql.AppendFormat("left join codemapping c on v.Gender=c.Value and TableName='Volunteer' and ColumnName='Gender' ")
        sql.AppendFormat("where 1=1 ")

        If Me.VolunteerQueryControl1.OrganizationID <> "0" Then
            sql.AppendFormat("and (oo.DirectUOrganizationID = '{0}'  ) ", Me.VolunteerQueryControl1.OrganizationID)
        End If

        If Me.txtVolunteerName.Text.Trim <> "" Then
            sql.AppendFormat("and v.PureVolunteerName like '%{0}%' ", Me.txtVolunteerName.Text.Replace("'", "''").Trim())
        End If

        If Me.txtVolunteerID.Text.Trim <> "" Then
            sql.AppendFormat("and HC.VolunteerID = '{0}' ", Me.txtVolunteerID.Text.Replace("'", "''").Trim())
        End If

        Me.gv.DataSource = dat.GetData(sql)
        Me.gv.DataBind()
    End Sub
End Class
